// author by welong
// zuowl@qq.com
// 2014-09-12  10:54
// PAT basic 1015

#include <iostream>
#include <stdio.h>
#include <queue>

using namespace std;
#define TYPE 4

class Stu
{
public:
	Stu(int ii=0, int ie=0, int ia=0): \
		id(ii), ethics(ie), ability(ia){}

	void print() const
	{
		printf("%08d %d %d\n", id, ethics, ability);
	}

public:
	int id;
	int ethics;
	int ability;
};

inline bool operator< (const Stu &x, const Stu &y)
{
	int total_x = x.ethics + x.ability; 
	int total_y = y.ethics + y.ability;

	if(total_x != total_y)
		return total_x < total_y;
	else if(x.ethics != y.ethics)
		return x.ethics < y.ethics;
	else 
		return x.id > y.id;
}

int main(int arg, char **argv)
{
	priority_queue<Stu> q[TYPE];

	int N, L, H;
	scanf("%d%d%d", &N, &L, &H);
	int count = N;

	int id, ethics, ability, i, j = -1;
	for(i = 0; i < N; i++)
	{
		scanf("%d %d %d", &id, &ethics, &ability);
		
		if(ethics >= H && ability >= H) j = 0;
		else if(ethics >= H && ability >= L) j = 1;
		else if(ethics >= L && ability >= L)
		{
			if(ethics >= ability) j = 2;
			else j = 3;
		}
		else j = -1;
		
		if(j != -1)
			q[j].push(Stu(id, ethics, ability));
		else
			count--;
	}

	printf("%d\n", count);
	for(i = 0; i < TYPE; i++)
	{
		while(!q[i].empty())
		{
			q[i].top().print();
			q[i].pop();
		}
	}

	return 0;
}
